local helper=require('library.helpers')
local config=require('config.application')
local registry=require ('vanilla.v.registry'):new('application')
local CacheModule={}
function CacheModule:new(index)
	index=index or 1
	local cache_name='cacheObjInstance'..index
	local obj=registry:get(cache_name);
	if obj then
		return obj
	end
	local o={
		hander=self:createHander(config.cache.type,index)
	}
	setmetatable(o,{__index=self})
	registry:set(cache_name,o)
	return o
end

function CacheModule:createHander(type,index)
	local hander=require("library.cache."..type):new(config.cache[type][index])
	return hander
end

function CacheModule:get(key)
	return self.hander:get(key)
end

function CacheModule:set(key,val,ttl,tag)
	return self.hander:set(key,val,ttl,tag)
end

function CacheModule:exists(key)
	return self.hander:exists(key)
end

function CacheModule:del(key)
	return self.hander:del(key)
end

function CacheModule:clear_tag(tag)
	return self.hander:clear_tag(tag)
end

function CacheModule:clear()
	self.hander:clear()
end

return CacheModule